<?php

$nationlist = '';
$nationrows = Db::getRows('*', 'nation');
foreach ($nationrows as $nationrow) {
    $nationlist .= '<option value="'.$nationrow['id'].'">'.$nationrow['name'].'</option>';
}

if (Http::isPost()) {
    $nation = $_POST['nationlist'];
    $nationname = Db::getOneField('name', 'nation', 'id=' . $nation);
    $type = '9';
    $title = Form::input('title','ne');
    $level = Form::input('level');
    $intro = Form::input('intro');
    $content = Form::input('content');
    $title2 = Form::input('title2','ne');
    $intro2 = Form::input('intro2');
    $content2 = Form::input('content2');
    $posteddate = date('H:i d-m-Y');
    $img = '';
    if (Form::isValid()) {
        $curpath = $_SERVER['DOCUMENT_ROOT'] . str_replace('/admin', '/upload/', baseUrl());

        if ($_FILES["file"]["error"] > 0 && $_FILES["file"]["error"] != '4') {
            Js::alert( "Có lổi: " . $_FILES["file"]["error"] . "<br />");
        }
        else if ($_FILES["file"]["error"] == '4') {
            $eval = eval(Db::insert('article', array_merge(array('id'))));
                if (mysql_affected_rows() > 0) {
                    Js::alert(fl('success_insert'));
                    Js::GoUrl(baseUrl() . '/duhocList');
                    exit();
                }
        }else {
            $upload = Http::UploadImage('file', str_replace('//', '/', $curpath), '', $img);
            if ($upload === '') {
                $eval = eval(Db::insert('article', array_merge(array('id'))));
                if (mysql_affected_rows() > 0) {
                    Js::alert(fl('success_insert'));
                    Js::GoUrl(baseUrl() . '/duhocList');
                    exit();
                }
            } else {
                Js::alert($upload);
            }
        }
    }
}
?>
